package com.ljj.bitetime.ui.theme

import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext

private val LightColorScheme = lightColorScheme(
    primary = Color(0xFF8BC34A),            // 主要组件背景
    secondary = Color(0xFFFF9800),          // 突出显示背景
    tertiary = Color(0xFFFFD600),           // 辅助色
    background = Color(0xFFFFFFFF),         // 主背景
    surface = Color(0xFFF5F5F5),            // 表面背景
    onPrimary = Color(0xFF212121),          // 主要文字
    onSecondary = Color(0xFF212121),        // 次要文字
    onTertiary = Color(0xFF212121),         // 第三文字
    onBackground = Color(0xFF212121),       // 背景文字
    onSurface = Color(0xFF212121),          // 表面文字
    surfaceVariant = Color(0xFFE0E0E0),     // 表面变体
    onSurfaceVariant = Color(0xFF424242),   // 表面变体上的文字
    outline = Color(0xFF757575),            // 轮廓线颜色
    inverseSurface = Color(0xFF212121),     // 反转表面
    inverseOnSurface = Color(0xFFFFFFFF),   // 反转表面上的文字
    error = Color(0xFFB00020),              // 错误颜色
    onError = Color(0xFFFFFFFF)             // 错误文字颜色
)

private val DarkColorScheme = darkColorScheme(
    primary = Color(0xFF689F38),            // 主要组件背景
    secondary = Color(0xFFFFB74D),          // 突出显示背景
    tertiary = Color(0xFFFFEB3B),           // 辅助色
    background = Color(0xFF121212),         // 主背景
    surface = Color(0xFF1E1E1E),            // 表面背景
    onPrimary = Color(0xFFFFFFFF),          // 主要文字
    onSecondary = Color(0xFFFFFFFF),        // 次要文字
    onTertiary = Color(0xFFFFFFFF),         // 第三文字
    onBackground = Color(0xFFFFFFFF),       // 背景文字
    onSurface = Color(0xFFFFFFFF),          // 表面文字
    surfaceVariant = Color(0xFF2E2E2E),     // 表面变体
    onSurfaceVariant = Color(0xFFBDBDBD),   // 表面变体上的文字
    outline = Color(0xFF9E9E9E),            // 轮廓线颜色
    inverseSurface = Color(0xFFF5F5F5),     // 反转表面
    inverseOnSurface = Color(0xFF212121),   // 反转表面上的文字
    error = Color(0xFFCF6679),              // 错误颜色
    onError = Color(0xFF000000)             // 错误文字颜色
)

@Composable
fun BiteTimeTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    // Dynamic color is available on Android 12+
    dynamicColor: Boolean = false,
    content: @Composable () -> Unit
) {
    val colorScheme = when {
        dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
            val context = LocalContext.current
            if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
        }
        darkTheme -> DarkColorScheme
        else -> LightColorScheme
    }

    MaterialTheme(
        colorScheme = colorScheme,
        typography = Typography,
        content = content
    )
}